#include<bits/stdc++.h>
using namespace std;
#define int long long
//int a[200005];
int n, a, b, i, ans = INT_MIN;
signed main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (i ==  1) {
			b = a;
		} else {
			b = max(a, a + b);
		}
		ans = max(ans, b);
	}

	cout << ans;

	return 0;
}
